package com.top.mall.main.income

import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.BarUtils
import com.module.lemlin.owner.OwnerViewModeActivity
import com.top.mall.R
import com.top.mall.jetpack.vm.CouponViewModel
import kotlinx.android.synthetic.main.activity_coupon_discount.*
import kotlinx.android.synthetic.main.activity_coupon_discount.imageViewBack

class CouponDiscountActivity : OwnerViewModeActivity<CouponViewModel>() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, CouponDiscountActivity::class.java)
            activity.startActivity(intent)
        }
    }

    override fun viewModel(): CouponViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_coupon_discount

    override fun stateBar(): StatusBar {
        return StatusBar(view = flCouponDiscountBar)
    }

    override fun initView() {

        imageViewBack.setOnClickListener { finish() }
        //设置状态栏颜色
        BarUtils.setStatusBarColor(this, Color.WHITE)

        vpCouponDiscountBody.adapter = object : FragmentStatePagerAdapter(
            supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        ) {
            val tabs: MutableList<String> = mutableListOf<String>(
                "未使用", "已使用", "已过期"
            )

            override fun getItem(position: Int): Fragment =
                CouponFragment.newInstance()

            override fun getCount(): Int = tabs.size

            override fun getPageTitle(position: Int): CharSequence? {
                return tabs[position]
            }

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {}
        }

        tlCouponDiscountType.setupWithViewPager(vpCouponDiscountBody)
    }
}